//
//  ZXBasetypeExtension.swift
//  ExtensionTest
//
//  Created by ZX on 2025/2/10.
//

import Foundation
import UIKit


public extension CGSize {
    static func c(_ width: CGFloat, _ height: CGFloat) -> CGSize {
        return CGSize(width: width, height: height)
    }
    init(_ width: CGFloat, _ height: CGFloat) {
        self.init(width: width, height: height)
    }
}
public extension Bool {
    var toStr: String {
        return self ? "True" : "False"
    }
}


public protocol BaseTypeExchangeDelegate {
    var toTimeInterval: TimeInterval {get}
    var toCGFloat: CGFloat {get}
    var toInt: Int {get}
    var toString: String {get}
    var toFloat: Float {get}
    var toDouble: Double{get}
}

extension Int: BaseTypeExchangeDelegate{
    public var toFloat: Float {
        Float(self)
    }
    
    public var toTimeInterval: TimeInterval {
        TimeInterval(self)
    }
    public var toCGFloat : CGFloat {
        CGFloat(self)
    }
    public var toInt: Int{
        self
    }
    public var toString: String{
        String(self)
    }
    public var toDouble: Double{
        Double(self)
    }
}

public extension Int {
    var getHour : Int{
        self/3600
    }
    var getMinute: Int{
        (self%(3600))/60
    }
    var getSecond: Int{
        self%60
    }
    var twoDigitStr: String {
        return String(format: "%02d", self)
    }
}

extension Float: BaseTypeExchangeDelegate{
    public var toTimeInterval: TimeInterval {
        TimeInterval(self)
    }
    
    public var toCGFloat: CGFloat {
        CGFloat(self)
    }
    public var toInt: Int{
        Int(self)
    }
    public var toString: String{
        String(self)
    }
    public var toFloat: Float {
        Float(self)
    }
    public var toDouble: Double{
        Double(self)
    }
}
extension Double: BaseTypeExchangeDelegate{
    public var toTimeInterval: TimeInterval {
        TimeInterval(self)
    }
    
    public var toCGFloat: CGFloat {
        return self
    }
    public var toInt: Int{
        Int(self)
    }
    public var toString: String{
        let i = Float(self)
        return String(i)
    }
    public var toFloat: Float {
        Float(self)
    }
    public var toDouble: Double{
        self
    }
}
extension CGFloat: BaseTypeExchangeDelegate{
    
    public var toTimeInterval: TimeInterval {
        TimeInterval(self)
    }
    
    public var toCGFloat: CGFloat {
        return self
    }
    public var toInt: Int{
        Int(self)
    }
    public var toString: String{
        let i = Float(self)
        return String(i)
    }
    public var toFloat: Float {
        Float(self)
    }
    public var toDouble: Double{
        Double(self)
    }
}

extension String: BaseTypeExchangeDelegate{
    public var toCGFloat: CGFloat {
        let i = Float(self) ?? 0
        return CGFloat(i)
    }
    
    public var toString: String {
        self
    }
    
    public var toTimeInterval: TimeInterval {
        TimeInterval(self) ?? 0
    }
    public var toInt: Int{
        Int(self) ?? 0
    }
    public var toFloat: Float {
        Float(self) ?? 0
    }
    public var toDouble: Double{
        Double(self.toFloat)
    }
}




public extension Int{
    var xss: CGFloat{
        return self.toCGFloat * UIScreen.main.bounds.width / 375
    }
}

public extension CGFloat {
    var xss: CGFloat{
        return self.toCGFloat * UIScreen.main.bounds.width / 375
    }
}

public extension Double {
    var xss: CGFloat{
        return self.toCGFloat * UIScreen.main.bounds.width / 375
    }
}
